from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime
from .user import UserResponse
from .category import CategoryResponse
from .tag import TagResponse

class PostBase(BaseModel):
    title: str
    content: str
    excerpt: Optional[str] = None
    cover_image: Optional[str] = None
    is_published: bool = False
    is_featured: bool = False
    category_id: Optional[int] = None
    tag_ids: Optional[List[int]] = None

class PostCreate(PostBase):
    pass

class PostUpdate(BaseModel):
    title: Optional[str] = None
    content: Optional[str] = None
    excerpt: Optional[str] = None
    cover_image: Optional[str] = None
    is_published: Optional[bool] = None
    is_featured: Optional[bool] = None
    category_id: Optional[int] = None
    tag_ids: Optional[List[int]] = None

class PostResponse(PostBase):
    id: str
    view_count: int
    like_count: int
    created_at: datetime
    updated_at: Optional[datetime] = None
    published_at: Optional[datetime] = None
    author: Optional[UserResponse] = None
    category: Optional[CategoryResponse] = None
    tags: List[TagResponse] = []
    
    class Config:
        from_attributes = True

class PostList(BaseModel):
    id: str
    title: str
    excerpt: Optional[str] = None
    cover_image: Optional[str] = None
    is_published: bool
    is_featured: bool
    view_count: int
    like_count: int
    created_at: datetime
    published_at: Optional[datetime] = None
    author: Optional[UserResponse] = None
    category: Optional[CategoryResponse] = None
    tags: List[TagResponse] = []
    
    class Config:
        from_attributes = True
